package com.thinkingcoder.tccache.core.command.zset;

import static com.thinkingcoder.tccache.constant.CommandConstants.ZSetCmd.ZSCORE;

import com.thinkingcoder.tccache.core.TcCache;
import com.thinkingcoder.tccache.core.command.Command;
import com.thinkingcoder.tccache.core.model.Reply;

/**
 * ZSCORE command.
 */
public class ZScoreCmd implements Command {
    @Override
    public String name() {
        return ZSCORE;
    }

    @Override
    public Reply<?> exec(TcCache cache, String[] args) {
        String key = getKey(args);
        String val = getValue(args);
        Double zScore = cache.zScore(key, val);
        return Reply.string(zScore == null ? null : zScore.toString());
    }
}
